package com.link.base.base.visitplan.controller;

import com.link.base.base.visitplan.model.VisitRecord;
import com.link.base.base.visitplan.service.VisitRecordService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.query.Filter;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author unknown
 * @date unknown
 * @comments 拜访记录
 */
@Controller
@RequestMapping("/link/visitplan2")
public class VisitRecordController extends BasicController<VisitRecord> {

    @Resource
    private VisitRecordService visitRecordService;

    @Override
    public BasicService<VisitRecord> getBasicService() throws Exception {
        return visitRecordService;
    }

    /**
     * <p>Description</p>
     *
     * @author yrf
     * @param record
     * @param planNo
     * @param qps
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/queryListSelectByPlanNo")
    @ResponseBody
    public Map<String, Object> queryListSelect(@JsonParam VisitRecord record,@JsonParam  Long planNo,@JsonParam  QueryParams qps,
                                               HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        LCLogger.info().withMessageKey("queryListSelectByPlanNo")
                .withMessage("根据拜访计划【" + planNo + "】查询拜访记录信息").flush();
        Map<String, Object> result = new HashMap<String, Object>();
        List<VisitRecord> list = new ArrayList<VisitRecord>();
        if (planNo == null) {
            result.put("success", false);
            result.put("rows", list);
            result.put("result", "planNo 不能为空！");
            return result;
        }
        qps.addFilter(new Filter("planNo", String.valueOf(planNo)));
        record.setPlanNo(planNo);
        record.setPageFlag(false);
        return this.queryByExamplePage(qps, record, session, request, response);
    }


    /**
     * <p>重写根据客户查询拜访记录</p>
     *
     * @author yrf
     * @param record
     * @param qps
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/queryListByAcctNo")
    @ResponseBody
    public Map<String, Object> queryListByAcctNo(@JsonParam VisitRecord record,@JsonParam  QueryParams qps, HttpSession session,
                                                 HttpServletRequest request, HttpServletResponse response) {
        LCLogger.info().withMessageKey("queryListByAcctNo")
                .withMessage("根据客户【" + qps.getId() + "】查询拜访记录信息").flush();
        Long acctNo = qps.getId() == null ? 0L : qps.getId();
        qps.addFilter(new Filter("acctNo", acctNo == null ? "noMatchId" : String.valueOf(acctNo)));
        record.setAcctNo(acctNo);
        return this.queryByExamplePage(qps, record, session, request, response);
    }

}
